import { isDev } from '@/utils/is';
import { request } from '@/utils/http'

const account = {
    id: 1,
    name: "admin",
    roles: ["admin"],
    permissions: ["page1"]
};

export async function login(data) {
    if (isDev())
        return {
            code: 0,
            content: {
                token: "test_token",
                account: account
            }
        };

    return await request({
        url: '/auth/login',
        method: 'post',
        withoutToken: true,
        data
    });
}

export async function getAccountInfo() {
    return await request({
        url: '/oauth/info',
        method: 'get',
    });
}

export async function sendEmailCode(email) {
    return await request({
        url: '/oauth/email/code',
        method: 'post',
        data: {
            email: email
        }
    });
}

export async function bindEmail(code) {
    return await request({
        url: '/oauth/email/bind',
        method: 'post',
        data: {
            code: code
        }
    });
}

export async function refreshToken() {
    return await request({
        url: '/oauth/token/refresh',
        method: 'post',
    })
}

export async function getAccount() {
    return await request({
        url: '/oauth/info',
        method: 'get'
    });
}